package com.huangjian.controller;


import com.huangjian.pojo.Product;
import com.huangjian.service.ProductServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//提供Restfull服务!!
@RestController
public class ProductController {

    @Autowired
    private ProductServiceImpl productService;

    //获取一些配置的信息，得到一些具体微服务
    @Autowired
    private DiscoveryClient client;

    @PostMapping("/product/add")
    public boolean addProduct(Product product) {
        return productService.addProduct(product);
    }


    @GetMapping("/product/get/{id}")
    public Product getProduct(@PathVariable("id") Integer id) {
        Product product = productService.queryById(id);
        if (product == null) {
            throw new RuntimeException("Fail");
        }
        return product;
    }

    @GetMapping("/product/list")
    public List<Product> queryAll() {
        return productService.queryall();
    }

}
